﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using _01.策略模式.Entities;
using _01.策略模式.Enums;

namespace _01.策略模式
{
    /// <summary>
    /// 策略模式 - Strategy Pattern
    /// 业务场景
    /// 产品的价格根据不同的客户采用不同的策略
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            DbSession dbSession = new DbSession();
            dbSession.Database.CreateIfNotExists();

            #region 产品价格策略

            //Product product = new Product("泸州老窖", 100);

            //dbSession.Products.Add(product);
            //dbSession.SaveChanges();

            Product product = dbSession.Products.First();

            product.ApplyDiscount(CustomerType.Trade);
            DbEntityEntry entry = dbSession.Entry<Product>(product);
            entry.State = EntityState.Modified;

            dbSession.SaveChanges();


            Console.WriteLine(product.Price);
            Console.WriteLine(product.SellingPrice);

            Console.ReadKey();

            #endregion


            #region 订单价格策略

            //Customer stardardCustomer = new Customer("李雷", CustomerType.Standard);
            //Customer tradeCustomer = new Customer("韩梅梅", CustomerType.Trade);

            //Order order1 = new Order(stardardCustomer);
            //Order order2 = new Order(tradeCustomer);

            //order1.ApplyCustomerDiscount();
            //order1.ApplyLargeOrderDiscount();

            //order2.ApplyCustomerDiscount();

            //dbSession.Customers.Add(stardardCustomer);
            //dbSession.Customers.Add(tradeCustomer);
            //dbSession.Orders.Add(order1);
            //dbSession.Orders.Add(order2);

            //dbSession.SaveChanges();

            //Console.WriteLine(order1.SettlementAmount);
            //Console.WriteLine(order2.SettlementAmount);

            //Console.WriteLine("OK");
            //Console.ReadKey();

            #endregion
        }
    }
}
